#!/bin/bash
SOCKETS=`lscpu | grep "Socket(s):"  | cut -d : -f 2 | awk '{print $1}'`
THREADSPERCORE=`lscpu | grep "Thread(s) per core:" | cut -d : -f 2 | awk '{print $1}'`
CORESPERSOCKET=`lscpu | grep "Core(s) per socket:" | cut -d : -f 2 | awk '{print $1}'`
echo "{"
echo "  \"cpu_topology\": {"
echo "    \"sockets\": \"$SOCKETS\","
echo "    \"cores_per_socket\": \"$CORESPERSOCKET\","
echo "    \"threads_per_core\": \"$THREADSPERCORE\"",
echo "    \"physical_cores\": \"$(expr $SOCKETS \* $CORESPERSOCKET)\"",
echo "    \"logical_cpus\": \"$(expr $SOCKETS \* $CORESPERSOCKET \* $THREADSPERCORE)\""
echo "  },"
echo "  \"gpu_topology\": ["
gpus=$(for i in `lspci | grep -E "(3D|VGA compatible) controller: NVIDIA" | awk '{print $1}' | sed 's/^0000://g' | cut -d : -f 1`; do \
    echo -n \"$(cat /sys/class/pci_bus/0000:$i/cpulistaffinity)\",; done | sed 's/,$//')
echo "    $gpus"
echo "  ]"
echo "}"

